//
//  UUBadgeManager.m
//  UUCharterSupplier
//
//  Created by ZhangAo on 11/03/2018.
//  Copyright © 2018 UUCharter. All rights reserved.
//

#import "UUBadgeManager.h"
#import "UUNotificationManager.h"
#import "AppDelegate.h"
#import <WZLBadge/WZLBadgeImport.h>

@interface UUBadgeManager () <UUNotificationManagerObserver>

@end

@implementation UUBadgeManager

- (instancetype)init {
    self = [super init];
    if (self) {
        [GetNotificationManager() addObserver:self];
    }
    
    return self;
}

#pragma mark - UUNotificationManagerObserver methods

- (void)notificationManagerDidUpdateUnreadCount {
    UUNotificationUnreadCountModel *unreadCount = [GetNotificationManager() fetchNotificationUnreadCount];
    
    UITabBarItem *item = GetAppDelegate().tabBarController.tabBar.items[UUTabBarTypeNotification];
    if (unreadCount.message + unreadCount.product + unreadCount.news > 0) {
        [item showBadgeWithStyle:WBadgeStyleRedDot value:1 animationType:WBadgeAnimTypeNone];
    } else {
        [item clearBadge];
    }
}

@end
